$(function () {
    obj.init();
});

var obj = new function() {
    'use strict';
    return {
        dataGrid: null,
        params: {
            schoolId: null,
            classId: null,
            groupId: null
        },
        dom: {
            save: null
        },
        init: function () {
            this.params.schoolId = xhTool.getQuery('schoolId');
            this.params.classId  = xhTool.getQuery('classId');
            this.params.groupId  = xhTool.getQuery('groupId');

            this.dom.save = window.top.xhTop.getModalConfirmDom();

            this.dataGrid = new xhDataGrid($('#list'), 'stats_brush/getBrushGroupUser', $.extend({}, this.params, {type: 'out'}));
            this.dataGrid.init().activeBtn(this.dom.save, null, 'bs');

            this.listener();
        },
        listener: function () {
            var $this = this;
            //保存按钮
            $this.dom.save.click(function () {
                $this.funObj().addGroupUser();
            });
        },
        funObj: function () {
            var $this = this;
            return {
                addGroupUser: function () {
                    var ids = $this.dataGrid.getSelectValues('iUserId');
                    if (!ids) {
                        window.top.xhTop.showError('无选中用户！');
                        xhExtra.setBtnNormal($this.dom.save);
                        return false;
                    }
                    xhExtra.ajaxRequest('stats_brush/addBrushGroupUser', {studId: ids, groupId: $this.params.groupId}, {check: false}, function (data) {
                        if (xhExtra.checkError(data)) {
                            xhExtra.setBtnNormal($this.dom.save);
                            return false;
                        }
                        window.top.xhTop.getActiveFrame().obj.dataGrid.reload();
                        window.top.xhTop.closeModal();
                    });
                }
            }
        }
    }
};